package com.service.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;

import com.dao.AdminTypeDao;
import com.po.Goods;
@Service("adminTypeService")
@Transactional
public class AdminTypeServiceImpl implements AdminTypeService{
	@Autowired
	private AdminTypeDao adminTypeDao;

	@Override
	public String toAddType(Model model) {
		model.addAttribute("allTypes", adminTypeDao.selectGoodsType());
		return "admin/addType";
	}
	

	@Override
	public String toAddDepartmentType(Model model) {
		model.addAttribute("allTypes", adminTypeDao.selectDepartmentType());
		return "admin/addDepartmentType";
	}
	
	@Override
	public void toAddType1(Model model) {
		model.addAttribute("allTypes", adminTypeDao.selectGoodsType());
	
	}
	
	@Override
	public String selectGoodsByType(Model model, Integer id) {


		model.addAttribute("allGoods", adminTypeDao.selectGoodsByType(id));

		return "admin/selectGoods1";

	}


	@Override
	public String addType(String typename, Model model, HttpSession session) {
		adminTypeDao.addType(typename);
		//添加商品与修改商品页面使用		
		return "forward:/adminType/toAddType";
	}

	@Override
	public String addDepartmentType(String dept_name, Model model, HttpSession session) {
		adminTypeDao.addDepartmentType(dept_name);
		//添加商品与修改商品页面使用	
		return "forward:/adminType/toAddDepartmentType";
	}
	
	@Override
	public String toDeleteType(Model model) {
		model.addAttribute("allTypes", adminTypeDao.selectGoodsType());
		return "admin/deleteType";
	}

	@Override
	public String deleteType(Integer id, Model model) {
		//类型有关联
		if(adminTypeDao.selectGoodsByType(id).size() > 0) {
			model.addAttribute("msg", "类型有关联，不允许删除！");
			return "forward:/adminType/toDeleteType";
		}
		if(adminTypeDao.deleteType(id) > 0) 
			model.addAttribute("msg", "类型成功删除！");
		//回到删除页面
		return "forward:/adminType/toDeleteType";
	}


	@Override
	public String toDeleteDepartmentType(Model model) {
		model.addAttribute("allTypes", adminTypeDao.selectDepartmentType());
		return "admin/deleteDepartmentType";
	}


	@Override
	public String deleteDepartmentType(Integer id, Model model) {
		
		if(adminTypeDao.deleteDepartmentType(id) > 0) 
			model.addAttribute("msg", "类型成功删除！");
		//回到删除页面
		return "forward:/adminType/toDeleteDepartmentType";
	}

//	@Override
//	public String toSelectGoodsByType(Model model) {
//		model.addAttribute("allGoods", adminTypeDao.selectGoodsTable());
//		return "admin/selectGoods1";
//	}




	
}
